/* 
 * Copyright (c)	Insighten Intelligent Equipment co.,LTD
 * 
 *  Use of this software is controlled by the terms and conditions found
 *  in the license agreement under which this software has been supplied.
 * 
 */
/** 
 * @file msg_svr_main.c
 * @brief test message library functions
 * @author taco [tacoee@gmail.com]
 * @version 0.1
 * @date 2010-09-13
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>

#include "types.h"
#include "message.h"
#include "msg.h"

int main(int argc, char *argv[])
{
	Message *msg = NULL;
	MsgContex *mcp = NULL;
	int i;
	int j = 0;
	
	msg = msg_create(MSG_KEY, sizeof(MsgContex));

	if (msg != NULL) {
		mcp = (MsgContex *)msg->msg_t;
	}

	while(j < 10) {
		if (msg_rcv(msg, MSG_TYPE_SVR) < 0) {
			perror("Rcevice.");
			break;
		}
		fprintf(stdout,"%s\n", mcp->m);
		system("ipcs");

		for(i=0; i < mcp->m_len; i++) {
			mcp->m[i] = toupper(mcp->m[i]);
		}
		mcp->des = mcp->src;
		mcp->src = MSG_TYPE_SVR;

		if(msg_send(msg) < 0) {
			perror("Send.");
			break;
		}
		j++;

	}
	msg_destory_deeply(msg);

	return 0;
}
